package com.example.playerdemo.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

import com.lecloud.lecloudsdkdemo.R;
import com.letv.controller.PlayProxy;
import com.letv.simple.utils.LetvParamsUtils;
import com.letv.simple.utils.SharedPreferenceUtil;
import com.letv.universal.iplay.EventPlayProxy;

public class MobilePlayActivity extends Activity implements OnClickListener {
	private static final String TAG = "MobilePlayActivity";
	private ImageView back;
	private TextView title;
	private Button startMobileLive;
	private Button startMobileLive0;
	private EditText path_content;
	boolean hasSkin;
	// String playpath =
	// "rtmp://183.mpull.live.lecloud.com/live/sdjjdhh?tm=20160415171459&sign=b3c61964f261b1966fa550ef9be1d6fc";
	String playpath = "rtmp://12438.mpull.live.lecloud.com/live/111?tm=20160927161925&sign=226f81c068474b895c6a654da7e57bd5";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Log.e(TAG, "onCreate()===");
		setContentView(R.layout.mobile_live);
		hasSkin = getIntent().getBooleanExtra("hasSkin", false);
		initView();
		setOnClickListener();
	}

	private void setOnClickListener() {
		back.setOnClickListener(this);
		startMobileLive.setOnClickListener(this);
		startMobileLive0.setOnClickListener(this);
	}

	private void initView() {
		path_content = (EditText) findViewById(R.id.path_content);
		path_content.setText(playpath);
		startMobileLive = (Button) findViewById(R.id.startMobileLive);
		startMobileLive0 = (Button) findViewById(R.id.startMobileLive0);
		back = (ImageView) findViewById(R.id.back);
		title = (TextView) findViewById(R.id.title);
		if (hasSkin) {
			title.setText(getResources().getString(
					R.string.mobile_player_hasSkin));
		} else {
			title.setText(getResources().getString(
					R.string.mobile_player_noSkin));
		}
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

	@Override
	public void onClick(View v) {
		int i = v.getId();
		if (i == R.id.back) {
			MobilePlayActivity.this.finish();

		} else if (i == R.id.startMobileLive) {
			if (TextUtils.isEmpty(path_content.getText().toString().trim())) {
				Toast.makeText(MobilePlayActivity.this, "播放地址为空,不能播放..",
						Toast.LENGTH_SHORT).show();
				return;
			}
			startLeCloudMobileLive(true);

		} else if(i==R.id.startMobileLive0){
			startLeCloudMobileLive(false);
		}
	}

	/**
	 * 乐视云移动直播
	 */
	private void startLeCloudMobileLive(boolean hasPath) {
		Intent intent = getStartActivity();
		Bundle mBundle = null;
		mBundle = new Bundle();
		mBundle.putInt(PlayProxy.PLAY_MODE, EventPlayProxy.PLAYER_LIVE);
		if(hasPath){
			 mBundle.putString("path", path_content.getText().toString().trim());
		}else{
			mBundle.putString("path", "rtmp://live.hkstv.hk.lxdns.com/live/hks");
		}
		intent.putExtra(PlayActivity.DATA, mBundle);
		startActivity(intent);
	}

	private Intent getStartActivity() {
		// return hasSkin ? new Intent(MobilePlayActivity.this,
		// PlayActivity.class)
		// : new Intent(MobilePlayActivity.this, PlayNoSkinActivity.class);
		return hasSkin ? new Intent(MobilePlayActivity.this,
				PlayActivity.class) : new Intent(MobilePlayActivity.this,
				PlayNoSkinActivity.class);
	}
}
